
package com.onlyxiahui.ability.basic.common.step;

/**
 * Description <br>
 * Date 2021-05-12 16:09:34<br>
 * 
 * @author XiaHui [onlovexiahui@qq.com]<br>
 * @since 1.0.0
 */

public class NextSyncStep<P, N> {

	private NextSyncRun<P, N> run;
	private NextSyncStep<N, ?> next;

	@SuppressWarnings("unchecked")
	public <V> NextSyncStep<N, V> add(NextSyncRun<P, N> run) {
		this.run = run;
		next = new NextSyncStep<>();
		return (NextSyncStep<N, V>) next;
	}

	public void run(P p) {
		if (null != run && null != next) {
			N n = run.execute(p);
			next.run(n);
		}
	}

	public static <P, N> NextSyncStep<P, N> build() {
		return new NextSyncStep<>();
	}
}
